<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="./layui/css/layui.css" media="all">
    <script src="./layui/layui.js"></script>
    <title>图表生成器</title>
    <script src="./js/echarts.js"></script>
    <script src="./js/vue-local.js"></script>
    <style>
        .layui-input {
            display: inline-block;
            width: 200px;
            height: 30px;
        }

        #app {
            vertical-align: top;
        }

        .configForm {
            margin: 20px;
            display: inline-block;
            width: 500px;
            height: 400px;
        }

        #main {
            position: absolute;
            right: 0px;
            top: 10px;
        }

        p {
            margin: 20px 40px;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="configForm">
            <form class="layui-form" action="">
                <p>
                    <input type="checkbox" name="title.text" lay-skin="primary" title="主题文字">
                    <input type="text" class="layui-input" id="title.text" onchange="change()" disabled="disabled">
                </p>
                <p>
                    <input type="checkbox" name="title.subtext" lay-skin="primary" title="副标题">
                    <input type="text" class="layui-input" id="title.subtext" onchange="change()" disabled="disabled">
                </p>
                <p>
                    <input type="checkbox" name="title.subtext" lay-skin="primary" title="副标题">
                    <input type="text" class="layui-input" id="title.subtext" onchange="change()" disabled="disabled">
                </p>
                <div class="layui-form-item">
                    <label class="layui-form-label">复选框</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="like[write]" title="写作">
                        <input type="checkbox" name="like[read]" title="阅读" checked>
                        <input type="checkbox" name="like[dai]" title="发呆">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">开关</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="switch" lay-skin="switch">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">单选框</label>
                    <div class="layui-input-block">
                        <input type="radio" name="sex" value="男" title="男">
                        <input type="radio" name="sex" value="女" title="女" checked>
                    </div>
                </div>
            </form>
        </div>
        <div id="main" style="width: 600px;height:400px;"></div>
    </div>
    <script>
        layui.use('form', function () {
            var form = layui.form;
            form.on('checkbox()', function (data) {
                let property = data.elem.name
                console.log(property);
                let value = document.getElementById(property).value
                if (data.elem.checked) {
                    document.getElementById(property).disabled = false
                    console.log(value)
                    eval(`option.${property}='${value}'`)
                } else {
                    document.getElementById(property).disabled = true
                    eval(`option.${property}=undefined`)
                }
                console.log(option)
                myChart.setOption(option);
            });
        });
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('main'));

        // 指定图表的配置项和数据
        var option = {
            title: {
                text: ''
            },
            tooltip: {},
            legend: {
                data: ['销量']
            },
            xAxis: {
                data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
            },
            yAxis: {},
            series: [{
                name: '销量',
                type: 'bar',
                data: [5, 20, 36, 10, 10, 20]
            }]
        };
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);


        function change() {
            let property = event.target.id
            let value = event.target.value || null
            console.log(value)
            eval(`option.${property}='${value}'`)
            console.log(option)
            myChart.setOption(option);
        }

        // 读取其他值进行修改
    </script>
</body>

</html>